<?php include_once "top.php";
$shop=$db->ig2_want('mae_shop','id='.$_GET['id'].' and status=1');
if(!$shop) tellgoto('','user.php');
?>
<div class="container">
	<div class="p3">
		<img class="p3bg bg" src="images/p3bg.jpg">
		<div id="p3bar">
			<?php 
			$shop_users=$db->ig2_select('mae_role','shop_id='.$shop['id'].' and role_type!=1 and is_delete=0 order by sort_id desc');
			foreach($shop_users as $list){
				$user=$db->ig2_want('mae_user','id='.$list['uid'].' and is_delete=0');
                if ($user) {
                    $stime=date('Y-m-01', strtotime(date("Y-m-d")));//当月开始时间 Y-m-d格式
                    $etime=strtotime("$stime +1 month");//当月结束时间 时间戳
                    $stime=strtotime($stime);//当月开始时间 时间戳

                    $sql='SELECT count(*) as total FROM mae_sell WHERE uid = "'.$user['id'].'" and create_time >= "'.$stime.'" and create_time < "'.$etime.'"';
                    $total=$db->ig2_query_select($sql);
			?>
			<div id="li_<?php echo $user['id']?>"><li>
				<img class="bt p3_1" src="images/p3_1.jpg" onclick="location.href='clerk.php?id=<?php echo $user['id']?>&source=admin'">
				<img id="user_<?php echo $user['id']?>" class="bt p3_2" src="images/p3_2.jpg">
				<span class="p2text p3text_1" ><?php echo $user['name']?></span>
				<span class="txt p3text_2" ><?php 
				if($user['score']>=6000) echo '三';
				else if($user['score']>=2500 && $user['score']<=5999) echo '二';
				else if($user['score']<=2499) echo '一';
				?>级大师</span>
				<span class="p2text p3text_3" >现有积分：<?php echo $user['score']-$user['used_score']?></span>	
				<span class="p2text p3text_4" >本月销量：<?php echo $total[0]['total']?></span>				
			</li></div>
			<?php }}?>
		</div>
		<img id="p3mbbg" class="bg" src="images/p3mbbg.png">
		<img id="p3mb_1" src="images/p3mb_1.png">
		<img id="p3mb_2" src="images/p3mb_2.png">
   		<div id="footer">
	   	 	<span class="p2text" id="fttext">还能再添加<span id="syme"><?php $count=count($shop_users); echo 5-$count?></span>个员工</span>
			<img id="ftbg" src="images/ftbg.jpg">
			<div id="count"><?php echo $count<5?'<img id="ftbt" src="images/ftbt.jpg">':''?></div>
		</div>
		<div id="ew">
	   		<img id="ewbg" src="images/ewbg.jpg">
			<img id="ew_1" src="repaircode/<?php echo $shop['tid']?>.jpg">
			<img id="ew_2" src="images/ew_2.jpg">
			<span id="ewtext"><span id="have"><?php echo $count?></span>/5</span>
		</div>
	</div>
</div>
<script type="text/javascript">
var id;
$('#ftbt').click(function(){
	document.getElementById('ftbt').src='images/ftbt_h.jpg';
	setTimeout("document.getElementById('ftbt').src='images/ftbt.jpg'",1000);
	$('#ew').fadeIn(500);
});

$('#p3_2').click(function(){
	$('#ew').fadeOut(500);
});

$('#ewbg').click(function(){
	$('#ew').fadeOut(500);
});

$('#p3mb_1').click(function(){
	document.getElementById('p3mb_1').src='images/p3mb_1_h.png';
	setTimeout("document.getElementById('p3mb_1').src='images/p3mb_1.png'",1000);
	$('#p3mbbg,#p3mb_1,#p3mb_2').fadeOut(500);
});
$('.p3_2').click(function(){
	//var id=$(this).attr('id').substr(5);
	//document.getElementById('user_'+id).src='images/p3_2_h.jpg';
	//setTimeout("document.getElementsByClassName('p3_2').src='images/p3_2.jpg'",1000);
	$('#p3mbbg,#p3mb_1,#p3mb_2').fadeIn(500);
	id=$(this).attr('id').substr(5);
});

$('#p3mb_2').click(function(){
	document.getElementById('p3mb_2').src='images/p3mb_2_h.png';
	setTimeout("document.getElementById('p3mb_2').src='images/p3mb_2.png'",1000);
	$('#p3mbbg,#p3mb_1,#p3mb_2').fadeOut(500);
	deluser(id);
});

setInterval("selusersurplu('<?php echo $shop['id']?>')",5000);

//查询剩余店员数
function selusersurplu(shop_id){
	$.ajax({
		type: "GET",
		url: "ra_ajax.php?sel_user_surplu=1&shop_id="+shop_id,
		dataType:'json',
		success: function(data){
			if(data.result == 'success'){
				$('#syme').html(5-parseInt(data.count));
				$('#have').html(parseInt(data.count));
				//$('#p3bar').html(data.str);
				if(data.count>=5) $('#count').html('');
				getWidth();
			}	
		}
	});
}

/* 2015年11月4日09:56:36 */
//替换店员
function deluser(id){
	$.ajax({
		type: "GET",
		url: "ra_ajax.php?del_user=1&id="+id,
		success: function(data){
			if(data == 'success'){
				var syme=parseInt($('#syme').html());
				$('#syme').html(syme+1);
				var have=parseInt($('#have').html());
				$('#have').html(have-1);
				$('#ew').fadeIn(500);
				$('#li_'+id).html('');
			}
		}
	});
}
/* 2015年11月4日09:56:36 */

function getWidth(){
	$('.p1,.p2,.p3,.p4,.container,.bg').width(x);
	$('.p1,.p2,.p3,.p4,.p5,.p6,.p7,.p8').css({left:0,top:0});
	//p3
	$('#p3bar').width(663/p).height(704/p).css({left:(x-663/p)/2+'px',top:200/p+'px'});
	$('#p3bar li').width(663/p).height(160/p).css({marginTop:15/p+'px'});
	$('.p3_1,.p3_2').width(103/p).height(50/p);
	$('.p3_1').css({left:419/p+'px',top:17/p+'px'});
	$('.p3_2').css({left:545/p+'px',top:17/p+'px'});
	$('.p3text_1').css({left:27/p+'px',top:27/p+'px',fontSize:35/p+'px'});
	$('.p3text_2').css({left:158/p+'px',top:46/p+'px',fontSize:20/p+'px'});
	$('.p3text_3').css({left:27/p+'px',top:97/p+'px',fontSize:26/p+'px'});
	$('.p3text_4').css({left:356/p+'px',top:97/p+'px',fontSize:26/p+'px'});
	$('#footer,#ftbg').width(x).height(232/p);
	$('#footer').css({left:0,bottom:0});
	$('#ftbt').width(663/p).height(76/p);
	$('#ftbt').css({left:(x-663/p)/2+'px',top:118/p+'px'});
	$('#fttext').css({left:(x-663/p)/2+'px',top:40/p+'px',width:663/p+'px',height:50/p+'px',fontSize:45/p+'px'});
	$('#ew').width(x).css({left:0,top:0});
	$('#ewbg').width(x);
	$('#ewtext').css({left:(x-120/p)/2+'px',top:660/p+'px',width:120/p+'px',fontSize:40/p+'px'});
	$('#ew_1').width(294/p).height(294/p).css({left:(x-294/p)/2+'px',top:171/p+'px'});
	$('#ew_2').width(185/p).height(78/p).css({left:(x-185/p)/2+'px',top:647/p+'px'});
	$('#p3mbbg').css({left:0,top:0});
	$('#p3mb_1').width(203/p).height(74/p).css({left:144/p+'px',top:630/p+'px'});
	$('#p3mb_2').width(203/p).height(74/p).css({left:402/p+'px',top:630/p+'px'});
}
</script>
</body>
</html>